Skip to content

docs: extend CONTRIBUTING.md with code guidelines#4202

Open
jlaportebot wants to merge 1 commit intogoogle:masterfrom
jlaportebot:docs/extend-contributing-guidelines
Open

docs: extend CONTRIBUTING.md with code guidelines#4202
jlaportebot wants to merge 1 commit intogoogle:masterfrom
jlaportebot:docs/extend-contributing-guidelines

Conversation

@jlaportebot
Copy link
Copy Markdown

Summary

This PR extends CONTRIBUTING.md with a comprehensive section on code guidelines and conventions, addressing issue #4023.

Changes

Added a new "Code Guidelines" section that documents:

  1. Naming Conventions

    • File names ({service}_{api}.go pattern)
    • Receiver names (consistently use 's')
    • Request option types
    • Request body types
    • Response types
    • Method and variable naming
    • Common variable names (owner, repo, org, user, team, project)
    • Enterprise and organization scoped methods
    • Common structs (ListOptions, ListCursorOptions, UploadOptions, Response)
  2. JSON Tags for Request Bodies

    • Required fields: non-pointer types without omitempty
    • Optional fields: pointer types with omitempty
    • Use omitzero for structs and slices
  3. URL Tags for Query Parameters

    • All fields should be non-pointer types with url tags
    • Use omitempty to omit zero values
  4. Pagination

    • Offset-based pagination (ListOptions)
    • Cursor-based pagination (ListCursorOptions)
    • Pagination best practices (embedding options, handling nil, using iterators)
  5. Common Types

    • ID fields: always int64
    • Node ID fields: always string
    • Timestamp fields: use Timestamp type
    • Boolean fields: always *bool
  6. Generation Patterns

    • Generated accessors
    • Generated iterators
    • Generated documentation
    • Linter rules (sliceofpointers, structfield)

Benefits

  • Helps new contributors understand the codebase better
  • Reduces review burden by making expectations explicit
  • Improves code consistency across the project
  • Documents patterns that are frequently discussed in reviews

Testing

This is a documentation-only change. No code changes or tests needed.

Closes #4023

Add comprehensive section documenting common code patterns and conventions:
- Naming conventions (files, receivers, types, methods, variables)
- JSON tags for request bodies (required vs optional fields, omitzero)
- URL tags for query parameters (non-pointer fields with omitempty)
- Pagination patterns (ListOptions, ListCursorOptions, best practices)
- Common types (ID, NodeID, Timestamp, boolean fields)
- Generation patterns (accessors, iterators, documentation, linter rules)

This addresses issue google#4023 and helps new contributors understand the codebase
better, reducing review burden and improving code consistency.
Copy link
Copy Markdown
Collaborator

@gmlewis gmlewis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, @jlaportebot.
LGTM.

cc: @alexandear

@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.71%. Comparing base (6c58592) to head (6fcb261).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4202   +/-   ##
=======================================
  Coverage   93.71%   93.71%           
=======================================
  Files         209      209           
  Lines       19772    19772           
=======================================
  Hits        18529    18529           
  Misses       1046     1046           
  Partials      197      197           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Copy Markdown
Contributor

@alexandear alexandear left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jlaportebot Thank you. I left a few comments regarding excessive formatting and redundant information. Could you also review the entire CONTRIBUTING.md document and consolidate duplicated content?

Also, I think this PR should be reviewed by everyone listed in the REVIEWERS file.

Comment thread CONTRIBUTING.md

[Go Doc Comments]: https://go.dev/doc/comment

## Code Guidelines
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the "Code Comments" section above should be under "Code Guidelines".

Comment thread CONTRIBUTING.md
Comment on lines +540 to +543
#### Generated Documentation

Documentation links are automatically generated from `openapi_operations.yaml`.
Run `script/generate.sh` to update these links.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines are not needed.

They are already in "Submitting a patch", "Metadata", and "Scripts".

Can be removed.

Comment thread CONTRIBUTING.md
Comment on lines +545 to +549
#### Linter Rules

The repository uses custom linter rules to enforce consistency:
- `sliceofpointers` - Ensures slice fields use pointers
- `structfield` - Ensures struct fields follow naming conventions
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have more linters. Let's simply remove this section.

Comment thread CONTRIBUTING.md
Comment on lines +332 to +333
State string `json:"state"` // Required field
// ...
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use TABs instead of spaces for all examples:

Suggested change
State string `json:"state"` // Required field
// ...
State string `json:"state"` // Required field
// ...

Comment thread CONTRIBUTING.md

### Naming Conventions

#### File Names
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we remove the "Other notes on code organization" section?

Comment thread CONTRIBUTING.md
Comment on lines +303 to +314
#### Enterprise and Organization Scoped Methods

Methods that operate on enterprise or organization resources include the scope
in their name:

```go
// Enterprise-scoped methods
func (s *EnterpriseService) GetLicenseInfo(ctx context.Context) (*LicenseInfo, *Response, error)

// Organization-scoped methods
func (s *OrganizationsService) ListMembers(ctx context.Context, org string, opts *OrganizationListMembersOptions) ([]*User, *Response, error)
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, I think this subsection may be incorrect - see #3761.

Comment thread CONTRIBUTING.md

When defining structs that represent a request body (sent via POST/PUT/PATCH):

1. **Required fields** should be non-pointer types without `omitempty`:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not use excessive LLM-like formatting:

Suggested change
1. **Required fields** should be non-pointer types without `omitempty`:
1. Required fields should be non-pointer types without `omitempty`:

Comment thread CONTRIBUTING.md
Comment on lines +448 to +457
2. **Handle nil options** in your methods:

```go
func (s *RepositoriesService) List(ctx context.Context, user string, opts *RepositoryListOptions) ([]*Repository, *Response, error) {
if opts == nil {
opts = &RepositoryListOptions{}
}
// ...
}
```
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be removed. We have the addOptions to handle nil options.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Extend CONTRIBUTING.md with common code guidelines

3 participants